//
//  B_addFhCell.m
//  Estate
//
//  Created by heyong on 16/8/9.
//  Copyright © 2016年 ttsx. All rights reserved.
//

#import "B_addFhCell.h"
#import "C_wladdCell_1.h"
#import "B_wuLiaoCell.h"

@implementation B_addFhCell
-(UIView *)topView{
    if(_topView==nil){
        _topView=[[UIView alloc]initWithFrame:CGRECTS(0, 0, 375, 46)];
        _topView.backgroundColor=[UIColor colorWithRed:0.87 green:0.87 blue:0.87 alpha:1.00];
    }
    return _topView;
}
- (UILabel *)titLab{
    if(_titLab==nil){
        _titLab=[[UILabel alloc]init];
        _titLab.font=[UIFont systemFontOfSize:15.];
    }
    return _titLab;
}
- (UIButton *)dleBtn{
    if(_dleBtn==nil){
        _dleBtn=[[UIButton alloc]init];
    }
    return _dleBtn;
}
- (void)setSite:(site_05_fh *)site{
    _site=site;
    //赋值的同时，刷新cell内部tableView
    [self.tableView reloadData];
}

-(UITableView *)tableView{
    if(_tableView==nil){
        
        _tableView=[[UITableView alloc]initWithFrame:CGRECTS(0, 46,375,500)];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        [_tableView registerNib:[UINib nibWithNibName:@"C_wladdCell_1" bundle:nil] forCellReuseIdentifier:@"double"];
        [_tableView registerNib:[UINib nibWithNibName:@"B_wuLiaoCell" bundle:nil] forCellReuseIdentifier:@"text"];
        _tableView.bounces=NO;
    }
    return _tableView;
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        [self createView];
        self.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    
    return self;
}

-(void)createView{
    [self.contentView addSubview:self.topView];
    //颜色条
    UIView *line=[[UIView alloc]init];
    [self.topView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(0);
        make.top.mas_offset(0);
        make.bottom.mas_offset(0);
        make.width.offset(4);
    }];
    line.backgroundColor=[UIColor colorWithRed:0.07 green:0.53 blue:0.49 alpha:1.00];
    
    //文字
    [self.topView addSubview:self.titLab];
    [self.titLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.topView.mas_centerY);
        make.left.mas_equalTo(line.mas_right).mas_offset(10);
        make.width.mas_offset(60);
        make.height.mas_offset(40);
    }];
    
    //移除按钮
    [self.topView addSubview:self.dleBtn];
    [self.dleBtn setImage:[UIImage imageNamed:@"quxiao"] forState:UIControlStateNormal];
    [self.dleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.topView.mas_centerY);
        make.right.mas_offset(-10);
        make.width.offset(30);
        make.height.offset(30);
    }];
    [self.dleBtn addTarget:self action:@selector(dleAction) forControlEvents:UIControlEventTouchUpInside];
    
    //添加表格
    [self.contentView addSubview:self.tableView];
}

#pragma mark-methold
- (void)dleAction{
    if(self.deleteBlock){
        self.deleteBlock();
    }
}


#pragma mark-UITaleViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 6;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row==3||indexPath.row==4||indexPath.row==5){
        return 120*BIZ;
    }else{
        return 44*BIZ;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    long row=indexPath.row;
    if(row==0){
        
        C_wladdCell_1 *cell=[tableView dequeueReusableCellWithIdentifier:@"double" forIndexPath:indexPath];
        
        cell.leftConstraint.constant=0.;
        cell.text1Block=^(NSString *str){
            self.text1Block(str);
        };
        cell.text2Block=^(NSString *str){
            self.text2Block(str);
        };
        [cell configTitle:@"桩号" Andtitle2:@"桩底标高" AndText1:_site.zhuh AndText2:_site.zdbg];
        
        return cell;
        
    }
    else if (row==1){
        C_wladdCell_1 *cell=[tableView dequeueReusableCellWithIdentifier:@"double" forIndexPath:indexPath];
        cell.leftConstraint.constant=0.;

        cell.text1Block=^(NSString *str){
            self.text3Block(str);
        };
        
        cell.text2Block=^(NSString *str){
            self.text4Block(str);
        };
        
        [cell configTitle:@"沉渣厚度" Andtitle2:@"桩位偏差" AndText1:_site.czhd AndText2:_site.zwbc];

        return cell;
    
    }else if (row==2){
        C_wladdCell_1 *cell=[tableView dequeueReusableCellWithIdentifier:@"double" forIndexPath:indexPath];
        cell.leftConstraint.constant=0.;

        cell.text1Block=^(NSString *str){
            self.text5Block(str);
        };
            cell.text2Block=^(NSString *str){
            self.text6Block(str);
        };
        
        [cell configTitle:@"垂直度偏差" Andtitle2:@"桩顶标高" AndText1:_site.czdpc AndText2:_site.zdbgao];

        return cell;
    
    }else if (row==3){
        
        B_wuLiaoCell *cell=[tableView dequeueReusableCellWithIdentifier:@"text" forIndexPath:indexPath];
        cell.textValueChangedBlock=^(NSString *value){
            self.text7Block(value);
        };
        
        [cell setTitle:@"砼超灌情况" andPlaceHolder:@"请输入文字" andTextValue:_site.hcgqk];
        return cell;
    
    }else if (row==4){
        B_wuLiaoCell *cell=[tableView dequeueReusableCellWithIdentifier:@"text" forIndexPath:indexPath];
        cell.textValueChangedBlock=^(NSString *value){
            self.text8Block(value);
        };
        
        [cell setTitle:@"异常处理情况" andPlaceHolder:@"请输入文字" andTextValue:_site.yic];

        return cell;
    
    }else{
        B_wuLiaoCell *cell=[tableView dequeueReusableCellWithIdentifier:@"text" forIndexPath:indexPath];
        
        cell.textValueChangedBlock=^(NSString *value){
            self.text9Block(value);
        };
        
        [cell setTitle:@"其它" andPlaceHolder:@"请输入文字" andTextValue:_site.qita];
        return cell;
    }
}

/*
 *  此方法让cell横线置顶
 */
-(void)viewDidLayoutSubviews {
    
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
        
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])  {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}


@end
